<?php

namespace Biz\Libraries;

use Lumen\Core\Exceptions\BusinessException;

/**
 * LanguageUtil.
 *
 * @license [http://www.85do.com] [杭州永奥网络科技有限公司]
 * @copyright Copyright (c) 2018-2026 Hangzhou Yongao Technology Co., Ltd. All rights reserved.
 */
class LanguageUtil
{
    /**
     * 转换Form表单translations节点数据平铺到$data数组中.
     *
     * @param array $data
     *
     * @throws BusinessException
     *
     * @return array
     */
    public static function convertLanguagesData(array $data): array
    {
        if (! isset($data['languages'])) {
            throw new BusinessException('数组中必须包含 languages 节点');
        }

        $result    = [];
        $languages = $data['languages'];
        foreach ($languages as $key => $value) {
            $result[] = [
                'lang' => $value,
            ];
        }

        return $result;
    }
}
